<?
if (!isset($r)) $r = "../";

require_once($r."_engine/c_account.php");
$account = GetActiveAccount();

require_once($r."_engine/c_session.php");
require_once($r."_engine/functions.php");

define ("UPDATE_PROFILE_OK", 1);
define ("UPDATE_PROFILE_INCORRECT_PASSWORD", 2);
define ("UPDATE_PROFILE_INCORRECT_PASSWORD2", 3);

if (@$do_update)
{
	get_form_values($values, array(
		// General
		"first_name", "last_name", "email",
		// Contact info
		"user_addr1", "user_addr2", "user_city", "user_state",
		"user_zip", "user_country", "user_phone",
	));
	
	$account->Update($values) or die();
	
	
	$status = UPDATE_PROFILE_OK;
	
	if ($f_password_old != "" || $f_password != "")
	{
		// Process change password operation
		if ($account->data["password"] != $f_password_old) {
			$status = UPDATE_PROFILE_INCORRECT_PASSWORD;
		}
		else {
			if ($f_password != $f_password2) {
				$status = UPDATE_PROFILE_INCORRECT_PASSWORD2;
			}
			else {
				$account->Update(array("password"=>$f_password)) or die();
				$g_session->Set($account->id, $account->data["password"], false);
			}
		}
	}
	
	
	if ($status == UPDATE_PROFILE_OK)
		generate_html_redirect("dashboard.php");
}
?>